#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QMenuBar* menuBar = new QMenuBar();
    this->setMenuBar(menuBar);

    QMenu* menuParent = new QMenu("父菜单");
    QMenu* menuChild = new QMenu("子菜单");
    menuBar->addMenu(menuParent);
    menuParent->addMenu(menuChild);

    QAction* act1 = new QAction("菜单项1");
    // 设置图标
    act1->setIcon(QIcon(":/open.png"));
    QAction* act2 = new QAction("菜单项2");
    act2->setIcon(QIcon(":/save.png"));
    menuParent->setIcon(QIcon(":/open.png"));
    menuChild->addAction(act1);
    menuChild->addAction(act2);

    QMenu* menuChild2 = new QMenu("子菜单2");
    menuChild->addMenu(menuChild2);
    menuChild->setIcon(QIcon(":/open.png"));
    QAction* act3 = new QAction("父菜单项");
    menuParent->addAction(act3);
}

MainWindow::~MainWindow()
{
    delete ui;
}

